﻿using System.Linq;
using System.Collections.Generic;
using VideoSeller.Business.Data;
using VideoSeller.Business.Data.Enums;
using VideoSeller.Business.Models;
using VideoSeller.Core.Configuration;
using System.Text;
using System;
namespace VideoSeller.Business.Data
{
	public partial class Client
	{
		public string FullName
		{
			get
			{
				var name = string.Format("{0} {1}", FirstName, LastName);
				return string.IsNullOrEmpty(name.Trim()) ? Login : name;
			}
		}
        public bool sFirstName {get {return ShowToOther.Contains("Fn");}}
        public bool sLastName {get {return ShowToOther.Contains("Ln");}}
        public bool sLogin {get {return ShowToOther.Contains("Lo");}}
        public bool sBirthDate {get {return ShowToOther.Contains("Bd");}}
        public bool sAddress { get { return ShowToOther.Contains("Ad"); } }
        public int m_Rating
        {
            get
            {


                int cnt = m_countAll;
                if (cnt == 0)
                    return 0;
                int cx = myVideos.Sum(m => m.ViewCnt == null ? 0 : m.ViewCnt.Value);
                if (cx == 0)
                    return 0;
                else
                    return cx / cnt;

            }
        }
        public int c_Rating
        {
            get
            {


                int cnt = c_countAll;
                if (cnt == 0)
                    return 0;
                int cx = conferenceVideos.Sum(m => m.ViewCnt == null ? 0 : m.ViewCnt.Value);
                if (cx == 0)
                    return 0;
                else
                    return cx / cnt;

            }
        }

        private IEnumerable<OnlineContent> _myVideos = null;
        private IEnumerable<OnlineContent> myVideos
        {
            get
            {
                if (_myVideos == null)
                    _myVideos = OnlineContents.Where(m => m.VideoContentType ==  VideoContentType.Free);
                return _myVideos;
            }
        }
        private IEnumerable<OnlineContent> _conferenceVideos = null;
        private IEnumerable<OnlineContent> conferenceVideos
        {
            get
            {
                if (_conferenceVideos == null)
                    _conferenceVideos = OnlineContents.Where(m => m.VideoContentType == VideoContentType.Paid);
                return _conferenceVideos;
            }
        }

        public int m_countAll { get { return myVideos.Count(); } }
        public int m_Views_anonce {get { return myVideos.Sum(m=>m.ViewCntA.HasValue ? m.ViewCntA.Value : 0);}}
        public int m_Views_online { get { return myVideos.Sum(m => m.ViewCnt.HasValue ? m.ViewCnt.Value : 0); } }
        public int m_Views_history { get { return myVideos.Sum(m => m.ViewCntH.HasValue ? m.ViewCntH.Value : 0); } }
        public int m_like { get { return myVideos.Sum(m=>m.Likes);} }
        public int m_nlike { get { return myVideos.Sum(m => m.UnLikes); } }
        public decimal m_VSM { get { return myVideos.Sum(m => m.CollectedMoney); } }
        public int c_countAll { get { return conferenceVideos.Count(); } }
        public int c_Views_anonce { get { return conferenceVideos.Sum(m => m.ViewCntA.HasValue ? m.ViewCntA.Value : 0); } }
        public int c_Views_online { get { return conferenceVideos.Sum(m => m.ViewCnt.HasValue ? m.ViewCnt.Value : 0); } }
        public int c_Views_history { get { return conferenceVideos.Sum(m => m.ViewCntH.HasValue ? m.ViewCntH.Value : 0); } }
        public int c_like { get { return conferenceVideos.Sum(m => m.Likes); } }
        public int c_nlike { get { return conferenceVideos.Sum(m => m.UnLikes); } }
        public decimal c_VSM { get { return conferenceVideos.Sum(m => m.CollectedMoney); } }
        public string language {
            get
            {
                var resourceModel = IoC.Resolve<ResourceModel>();
                var cultures = resourceModel.GetUniqueCultureInfos();
                System.Globalization.CultureInfo  ci= cultures.Where(m => m.Name == Culture).FirstOrDefault();
                return ci.NativeName.Split(new[] { " " }, 

                        StringSplitOptions.RemoveEmptyEntries)[0].Split(new[] { "(" }, StringSplitOptions.RemoveEmptyEntries)[0];

            }
        }
	}
}